package com.bw.kf.lib_base.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.cancel

abstract class BaseActivity<VDB : ViewDataBinding,VM: BaseViewModel>: AppCompatActivity(){
    lateinit var binding:VDB
    lateinit var viewModel:VM
    override  fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding= DataBindingUtil.setContentView(this,Layoutid())
        viewModel= ViewModelProvider(this)[getViewModel()]
        iniView()
        iniData()
    }
    abstract fun iniView()
    abstract fun iniData()
    abstract fun getViewModel(): Class<VM>
    abstract fun Layoutid(): Int
    override fun onDestroy() {
        super.onDestroy()
        binding.unbind()
        viewModel.viewModelScope.cancel()
    }
}
